<?php
namespace app\core;

class Log
{


    /**
     * 错误信息
     * @var array
     */
    private static $info = [];

    public static function log($logMsg)
    {

        if (isset($logMsg['path'])) {
            $logMsg['path'] = pathConvert($logMsg['path']);

        }
        self::$info[] = $logMsg;


        if ($logMsg['type'] == 'Notice') {
            return;
        }

        $error = sprintf(
            "文件路径；%s\n报错行数；%d\n错误信息；%s\n\n",
            $logMsg['path'],
            $logMsg['line'],
            $logMsg['message']
        );

        $filename = date('Y-m-d') . ".txt";
        $logDirectory = Config::get('log', 'error_log_file') . '/plugins';

        if (!is_dir($logDirectory) && !mkdir($logDirectory, 0777, true) && !is_dir($logDirectory)) {
            // Optionally handle the error
            return;
        }

        file_put_contents($logDirectory . DIRECTORY_SEPARATOR . $filename, $error, FILE_APPEND);
    }


    public static function getLog()
    {
        return self::$info;
    }


}